﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace DARE
{
    public class CHUDShader:
#if WINDOWS_PHONE
        BasicEffect
#else
        Effect
#endif
    {
        #region fields


        #endregion

        #region properties

        #region colors

#if WINDOWS_PHONE
        public Texture2D ColorMap
        {
            get
            {
                return Texture;
            }
            set
            {
                Texture = value;
            }
        }

        public Color HighLightColor
        {
            get
            {
                return new Color(EmissiveColor.X, EmissiveColor.Y, EmissiveColor.Z);
            }
            set
            {
                EmissiveColor = value.ToVector3();
            }
        }

        public bool IsHighLighted
        {
            get
            {
                return true;//return Parameters["_HighLight"].GetValueBoolean();
            }
            set
            {
                //Parameters["_HighLight"].SetValue(value);
            }
        }
#else
        public Texture2D ColorMap
        {
            get
            {
                return Parameters["_ColorMap"].GetValueTexture2D();
            }
            set
            {
                Parameters["_ColorMap"].SetValue(value);
            }
        }

        public Color HighLightColor
        {
            get
            {
                return new Color(Parameters["_HighLightColor"].GetValueVector4());
            }
            set
            {
                Parameters["_HighLightColor"].SetValue(value.ToVector4());
            }
        }

        public bool IsHighLighted
        {
            get
            {
                return Parameters["_HighLight"].GetValueBoolean();
            }
            set
            {
                Parameters["_HighLight"].SetValue(value);
            }
        }
#endif
        #endregion


        #endregion

        #region ctor

        protected CHUDShader(string shaderFile)
#if !WINDOWS_PHONE
            : base(CResourceMgr.Load<Effect>(shaderFile))
#else
            : base(new BasicEffect(DARE.CDare.Instance.GraphicsDevice))
#endif
        {

        }

        public CHUDShader()
#if !WINDOWS_PHONE
            : base(CResourceMgr.Load<Effect>(DARE.Properties.Resources.HUDShader, "Shaders/HUDShader"))
#else
            : base(new BasicEffect(DARE.CDare.Instance.GraphicsDevice))
#endif
        {
#if !WINDOWS_PHONE
            CurrentTechnique = Techniques["SimpleHUD"];
#endif
        }
        
        #endregion

        #region methods

        public virtual void Apply()
        {
            Matrix projection = Matrix.CreateOrthographicOffCenter(0, CDare.Instance.Config.Video.ResolutionWidth, CDare.Instance.Config.Video.ResolutionHeight, 0, 0, 1);
            Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);
#if WINDOWS_PHONE
            World = Matrix.Identity;
            View = Matrix.Identity;
            Projection = halfPixelOffset * projection;
#else
            Parameters["World"].SetValue(Matrix.Identity);
            Parameters["View"].SetValue(Matrix.Identity);
            Parameters["Projection"].SetValue(halfPixelOffset * projection);
#endif
            foreach (EffectPass pass in CurrentTechnique.Passes)
                pass.Apply();
        }

        #endregion
    }
}
